// 基于准备好的dom，初始化echarts实例
var myChart = echarts.init(document.getElementById('studentAttendenceCollage'),'walden');//定义折线图显示的位置对象
var option1 = {
    title: {
        text: '出勤率纵向比'
    },
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data:['正常','迟到','早退','调整']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    toolbox: {
        feature: {
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['周一','周二','周三','周四','周五','周六','周日']
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            show: true,
            interval: 'auto',
            formatter: '{value} %'
        },
    },
    series: [
        {
            name:'正常',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[120, 132, 101, 134, 90, 230, 210]
        },
        {
            name:'迟到',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[220, 182, 191, 234, 290, 330, 310]
        },
        {
            name:'早退',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[150, 232, 201, 154, 190, 330, 410]
        },
        {
            name:'调整',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[320, 332, 301, 334, 390, 330, 320]
        }
    ]
};

$(function () {
    $.ajax({
        url: baseURL + "/college/getAllcollege",
        data: {},
        success: function (r) {
            $("#option").append("<option value=''>全校</option>");
            for (i = 0; i < r.list.length; i++) {
                var tname = r.list[i].collegeName;
                var tid = r.list[i].collegeName;
                $("#option").append("<option value='" + tid + "'>" + tname + "</option>");
            }
        }
    });
    myChart.setOption(option1);
})
function query()
{
    $.ajax({
        url: baseURL + "TeacherPortrait/getTecaherAttendanceCollegeHorizontalComparison",
        data: {
            "collegeName":$("#option").val(),
            "startDate":$("#startDate").val(),
            "endDate":$("#endDate").val()
        },
        success: function (r) {
            option1.series=r.r.data;
            option1.xAxis= {
                type: 'category',
                data:r.r.xAxis
            };
            myChart.setOption(option1);
        }
    });
}
function setDate(id) {
    var Nowdate=new Date();
    M=Number(Nowdate.getMonth())+1;
    var today=Nowdate.getFullYear()+"-"+fix(M)+"-"+fix(Nowdate.getDate());
    if(id=='1'){
        $("#startDate").val(today);
        $("#endDate").val(today);
    }else if(id=='2'){
        $("#startDate").val(showWeekFirstDay());
        $("#endDate").val(today);
    }if(id=='3'){
        $("#startDate").val(showMonthFirstDay());
        $("#endDate").val(today);
    }
    query()
}
function showWeekFirstDay()
{
    var Nowdate=new Date();
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
    M=Number(WeekFirstDay.getMonth())+1
    return WeekFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(WeekFirstDay.getDate());
}
function showWeekLastDay()
{
    var Nowdate=new Date();
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
    var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
    M=Number(WeekLastDay.getMonth())+1
    return WeekLastDay.getFullYear()+"-"+M+"-"+WeekLastDay.getDate();
}
function showMonthFirstDay()
{
    var Nowdate=new Date();
    var MonthFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth(),1);
    M=Number(MonthFirstDay.getMonth())+1
    return MonthFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(MonthFirstDay.getDate());
}
function fix(num){
    if(num<10)
        return "0"+num;
    else return ""+num;
}
function showMonthLastDay()
{
    var Nowdate=new Date();
    var MonthNextFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth()+1,1);
    var MonthLastDay=new Date(MonthNextFirstDay-86400000);
    M=Number(MonthLastDay.getMonth())+1
    return MonthLastDay.getFullYear()+"-"+M+"-"+MonthLastDay.getDate();
}